package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.Get;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /*新增套餐*/
    @ApiOperation("新增套餐")
    @PostMapping()
    @CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("新增套餐:{}", setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }

    /*套餐分页查询*/
    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result PageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("套餐分页查询:{}", setmealPageQueryDTO);
        PageResult pageResult = setmealService.PageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /*套餐批量删除*/
    @ApiOperation("套餐批量删除")
    @DeleteMapping()
    @CacheEvict(cacheNames = "setmealCache",key = "#ids")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("套餐批量删除:{}", ids);
        setmealService.delete(ids);
        return Result.success();
    }
//    根据id查询套餐
    @ApiOperation("根据id查询套餐")
    @GetMapping("{id}")
    public Result<SetmealVO> queryById(@PathVariable Long id)
    {
       SetmealVO setmealVO= setmealService.queryById(id);
        return Result.success(setmealVO);
    }
    /**
     * 修改套餐
     *
     * @param setmealDTO
     */
    @ApiOperation("修改套餐")
    @PutMapping()
    
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐:{}",setmealDTO);
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
    /**
     * - 可以对状态为起售的套餐进行停售操作，可以对状态为停售的套餐进行起售操作
     * - 起售的套餐可以展示在用户端，停售的套餐不能展示在用户端
     * - 起售套餐时，如果套餐内包含停售的菜品，则不能起售
     * */
    @ApiOperation("起售停售套餐")
    @PostMapping("/status/{status}")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result startOrStop(@PathVariable Integer status , Long id){
        log.info("修改套餐:{},{}",status,id);
        setmealService.startOrStop(status,id);
        return Result.success();
    }


}
